﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace TheGameClient.WorldMap
{
	public partial class NetworkNode
	{
		public bool IsHomeSystem;
		private bool _alwaysShowLabel;
		public bool IsDragging;

		public NetworkNode()
		{
			InitializeComponent();
			RenderTransform = new ScaleTransform();
		}

		public string Hostname
		{
			get
			{
				if (txtHostName != null) return txtHostName.Text;
				return string.Empty;
			}

			set
			{
				if (txtHostName != null)
					txtHostName.Text = value;
			}
		}

		public string Corporation
		{
			get
			{
				if (txtCorpName != null) return txtCorpName.Text;
				return string.Empty;
			}

			set { if (txtCorpName != null) txtCorpName.Text = value; }
		}

		public ulong ComputerSystemId { get; set; }

		public Brush MarkerEdge { get; set; }

		public Brush MarkerFill
		{
			get { return marker.Fill; }
			set { marker.Fill = value; }
		}

		//private Color glowColor;
		//public Color GlowColor
		//{
		//    get
		//    {
		//        return glowColor;
		//    }

		//    set
		//    {
		//        if(Glow != null)
		//            Glow.Color = value;
		//        glowColor = value;
		//    }
		//}

		public bool AlwaysShowLabel
		{
			get { return _alwaysShowLabel; }

			set
			{
				_alwaysShowLabel = value;
				stkLabel.Visibility = _alwaysShowLabel ? Visibility.Visible : Visibility.Collapsed;
			}
		}

		public event EventHandler<MouseButtonEventArgs> OnMouseDown;
		public event EventHandler<MouseButtonEventArgs> OnMouseUp;
		public event EventHandler<MouseEventArgs> OnMouseMoving;

		protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
		{
			if (OnMouseDown != null)
				OnMouseDown(this, e);
			base.OnMouseLeftButtonDown(e);
		}

		protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
		{
			if (OnMouseUp != null)
				OnMouseUp(this, e);
			base.OnMouseLeftButtonUp(e);
		}

		protected override void OnMouseMove(MouseEventArgs e)
		{
			if (OnMouseMoving != null)
				OnMouseMoving(this, e);
			base.OnMouseMove(e);
		}

		protected override void OnMouseEnter(MouseEventArgs e)
		{
			stkLabel.Visibility = Visibility.Visible;
			base.OnMouseEnter(e);
		}

		protected override void OnMouseLeave(MouseEventArgs e)
		{
			if (!IsDragging && !AlwaysShowLabel)
				stkLabel.Visibility = Visibility.Collapsed;
			base.OnMouseLeave(e);
		}

		public Point GetPosition()
		{
			return new Point(Canvas.GetLeft(this), Canvas.GetTop(this));
		}
	}
}